
import AiChatView from '@/views/AiChatView.vue'
import AiLoginView from '@/views/AiLoginView.vue'
import AnotherComponent from '@/views/AnotherComponent.vue'
import TopicManager from '@/views/TopicManager.vue'
import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/TopicManager',
    name: 'TopicManager',
    component: TopicManager
  },
  {
    path: '/AnotherComponent',
    name: 'AnotherComponent',
    component: AnotherComponent
  },
  {
    path: '/AiChatView',
    name: 'AiChatView',
    component: AiChatView
  },
  {
    path: '/AiLoginView',
    name: 'AiLoginView',
    component: AiLoginView
  },
  {
    path: '/',
    redirect: '/AiLoginView'
  },
]

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})
// 根据sessionStorage.getItem('user')的值来判断用户是否登录
router.beforeEach((to, from, next) => {
  if (to.path !== '/AiLoginView' && !sessionStorage.getItem('user')) {
    next({ path: '/AiLoginView' })
  } else {
    next()
  }
})




export default router    